<%@ page contentType="text/html; charset=utf-8" language="java" errorPage="" %>
<%@ page import="java.sql.*"%> 
<%@page import="dataconn.dataconn"%> 
  <form name="grouplist" method="post" action="#">
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="table_style">
  <tr bgcolor="#52514E">
    <td colspan="6">所有分组列表<a></a></td>
  </tr>
  <tr bgcolor="#52514E">
    <td>编号</td>
    <td>分组名称</td>
    <td>分组用户</td>
    <td>所属项目</td>
    <td>&nbsp;</td>
  </tr>
 <%
int page_persize=5;//每页显示记录数
int page_total=0;//总的页数
int page_now=1;//当前页码
int rs_total=0;//总的记录数
//用户
dataconn con=new dataconn();
String sql="select GroupID,GroupName from TestGroup";
ResultSet rs=con.executeQuery(sql); 
rs.last();//指针到最后一条记录
rs_total=rs.getRow();//读出当前行号即总的记录数
//计算总页数
if (rs_total % page_persize==0)
page_total=rs_total/page_persize;
else
page_total=rs_total/page_persize+1; 

//得到当前的页码
try{
	if (!(request.getParameter("page_now")==null || request.getParameter("page_now").equals("")))
	page_now=Math.min(Math.abs(Integer.parseInt(request.getParameter("page_now"))),page_total);
}catch(java.lang.NumberFormatException e){
	out.print("指定页码格式不正确"+e);
}
if (page_now==0) page_now=1;
rs.absolute((page_now-1)*page_persize+1);
if (rs==null) 
out.print("对不起，暂时没有数据!");
else{
	for(int i=1;i<=page_persize;i++)
	{
	String GroupID=rs.getString("GroupID");
	String GroupName=rs.getString("GroupName");			
%>
  <tr bgcolor="#52514E">
    <td><%=GroupID %></td>
    <td><%=GroupName %></td>
    <td>
        <select class="selectlist2">
<%
String sql1="select UserName from TestGroup,Group_User,TestUser where Group_User.GroupID=TestGroup.GroupID and Group_User.UserID=TestUser.UserID and TestGroup.GroupID="+GroupID;
ResultSet rs1=con.executeQuery(sql1);
if(rs1==null)
{%>
      <option></option>
<%}
else{
{
   while(rs1.next())
   {
%>
    <option><%=rs1.getString("UserName")%></option>

<%} 
}
}

 %>
     </select>
    </td>
    <td>
        <select class="selectlist2">
<%
String sql3="select ProjectName from TestGroup,Group_Project,TestProject where Group_Project.GroupID=TestGroup.GroupID and Group_Project.ProjectID=TestProject.ProjectID and TestGroup.GroupID="+GroupID;
ResultSet rs3=con.executeQuery(sql3);
if(rs3==null)
{%>
      <option></option>
<%}
else{
{
   while(rs3.next())
   {
%>
    <option><%=rs3.getString("ProjectName")%></option>

<%} 
}
}

 %>
     </select>
    </td>
    <td><a href="ManageGroup.jsp?GroupID=<%=GroupID%>">编辑</a>&nbsp;&nbsp;<a href="group_del.jsp?GroupID=<%=GroupID%>">删除</a></td>
    <%
if (!rs.next()) break;
	}
}
rs.close();
%>
<p align=center>
<%
//显示页码导航，其中的问号表示由当前页面处理。
out.print("总共"+rs_total+"条记录　");
if (page_total>1){
out.print("当前第"+page_now+"页　");
out.print("共"+page_total+"页　");
if(page_now!=1) {
		out.print("<a href=?page_now=1>首页</a>　");
		out.print("<a href=?page_now="+(page_now-1)+">上一页</a>　");
	}
if(page_now!=page_total){
	out.print("<a href=?page_now="+(page_now+1)+">下一页</a>　"); 
	out.print("<a href=?page_now="+page_total+">尾页</a>　");
	} 
%>
<form action="#" method="post"><!--问号表示由当前页面处理 -->
	<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
	  <tr>
		<td><div align="center">跳转到：
		  <input name="page_now" type="text" size="3" />
				<input name="submit" type="submit" value="提交" />
		</div></td>
	  </tr>
	</table>
</form>
</tr>

<% } %>
</table>  </form>